package Demo1;


/**
 * @Author 12629
 * @Description：
 */

class Animal {
    public String name;
    public int age;
    public String color;

    /*public Animal() {

    }*/
    /*static {
        System.out.println("Animal的静态代码块！");
    }

    {
        System.out.println("Animal的实例代码块！");
    }*/

    public Animal(String name) {
        this.name = name;
        System.out.println("Animal(String)");
    }

    public void eat() {
        System.out.println(name+" 正在吃饭！---Animal");
    }
}

class Dog extends Animal{

    /*static {
        System.out.println("Dog的静态代码块！");
    }

    {
        System.out.println("Dog的实例代码块！");
    }*/
    public Dog(String name) {
        super(name);
        System.out.println("DOG的构造方法！");
    }

    /*public Dog() {
        //super();

    }*/
    public void wangWang() {
        System.out.println(name+" 正在旺旺旺！！");
        /*super.name = "12";
        this.eat();*/
    }
    public void eat() {
        System.out.println(name+" 正在吃狗粮！");
    }
}
class Cat extends Animal{
    public Cat(String name) {
        super(name);
    }

    //..... 猫自己特有的属性

    public void miMi() {
        System.out.println(name +" 正在喵喵喵！");
    }
}

class Test {

    public static void main(String[] args) {
        /*Dog dog1 = new Dog("小狗1");

        Animal animal = dog1;*/


        //父类引用 引用了子类对象
        Animal animal1 = new Dog("小狗1");
        animal1.eat();//动态绑定



        /*Animal animal1 = new Animal("小狗1");
        animal1.eat();*/
        //animal1.wangWang(); 父类 此时只能调用父类的方法

    }
    public static void main3(String[] args) {

        System.out.println("=========");
        Dog dog2 = new Dog("小狗2");

    }
    public static void main2(String[] args) {
        Animal animal1 = new Animal("animal");
        /*System.out.println("=====");
        Animal animal2 = new Animal("animal");*/
    }


    public static void main1(String[] args) {
        Dog dog = new Dog("小狗");
        dog.eat();
        dog.wangWang();
        System.out.println("=========");
        Cat cat = new Cat("小猫");
        cat.miMi();
        cat.eat();
    }
}
